#include <stdio.h>
#include<time.h>
#include<getch.h>
#include<stdlib.h>

int main(int argc,const char* argv[])
{
	//定义迷宫地图
	char maze[10][10]={
		{1,1,1,1,1,1,1,1,1,1},
		{1,0,0,1,1,1,1,1,1,1},
		{1,1,0,1,1,1,1,1,1,1},
		{1,1,2,1,1,1,1,1,1,1},
		{1,1,0,1,1,1,1,1,1,1},
		{1,1,0,1,1,1,0,0,0,0},
		{1,1,0,1,1,1,0,1,1,1},
		{1,1,0,0,0,0,0,1,1,1},
		{1,1,1,1,1,1,1,1,1,1},
		{1,1,1,1,1,1,1,1,1,1},
		};
	//定义老鼠坐标
	int mouse_x = 3,mouse_y= 2;
	//获取开始时间
	time_t start_time = time(NULL);

	for(;;)
	{
		//清理屏幕
		system("clear");
		for(int i=0;i<10;i++)
		{
			for(int j = 0;j<10;j++)
			{
				switch(maze[i][j])
				{
					case 0:printf("  ");break;
					case 1:printf("# ");break;
					case 2:printf("@ ");break;
				}
			}
			printf("\n");
		}
		//获取方向键并处理
			if(5==mouse_x && 9 ==mouse_y)
			{
				time_t over_time=time(NULL);
				printf("游戏结束，成功找到出口\n 游戏共用时%lu",over_time-start_time);
				return 0;
			}
		switch(getch())
		{
			case 183 :
				if(0 ==maze[mouse_x-1][mouse_y] && 0!=mouse_x)
					{
						maze[mouse_x][mouse_y]=0;
						maze[--mouse_x][mouse_y]=2;
			
					}
				break;
			case 184 :
				if(0 ==maze[mouse_x+1][mouse_y] && 9 != mouse_x)

					{
				    	 maze[mouse_x][mouse_y]=0;
					   	maze[++mouse_x][mouse_y]=2;
					}
				break;
			case 185 :
				if(0 ==maze[mouse_x][mouse_y+1] && 9!= mouse_y)
				{
					  maze[mouse_x][mouse_y]=0;
					 maze[mouse_x][++mouse_y]=2;

				}
				break;
			case 186 :
				if(0 ==maze[mouse_x][mouse_y-1] && 0!= mouse_y)
				{
					 maze[mouse_x][mouse_y]=0;
					maze[mouse_x][--mouse_y]=2;
		

				}
				break;
		}
		//判断是否到达出口 
	


}}
